package com.zs.task;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.system.comm.util.JedisUtil;
import com.system.common.pojo.BisCouponRecord;
import com.zs.service.BisCouponActiveService;

import redis.clients.jedis.Jedis;

@Component
public class TaskTest {
	
	@Autowired
	private BisCouponActiveService bisCouponActiveService;
	
	@Scheduled(cron="0 */30 * * * ?")
	public void TaskCycle(){
	       Jedis jedis=JedisUtil.getJedisClient();
	       String date=jedis.get("validDate");
	       List<Map<String,Object>> activeList=bisCouponActiveService.queryByTime();
	       for (Map<String, Object> active : activeList) {
			   Date createtime=(Date)active.get("create_time");
			   Calendar c = Calendar.getInstance();
		       c.setTime(createtime);
		       c.add(Calendar.DATE, Integer.parseInt(date));
		       Date createdate = c.getTime();
			   Date sysDate=new Date();
			  if (createdate.compareTo(sysDate)==-1) {
				BisCouponRecord record=new BisCouponRecord();
				record.setActiveId((String)active.get("active_id"));
				record.setStatus("3");				
				bisCouponActiveService.editByRecord(record);
			  }
		  }
     }	
}
